package com.future;

import java.util.ArrayList;
import java.util.List;

/**
 * Description: 78. 子集
 *
 * @author weiruibai.vendor
 * Date: 2022/6/11 15:01
 */
public class Solution_78 {

    public static void main(String[] args) {
        int[] nums = new int[]{1, 2, 3};
        System.out.println(subsets(nums));
    }

    public static List<List<Integer>> subsets(int[] nums) {
        List<List<Integer>> ans = new ArrayList<>();
        process(nums, 0, ans, new ArrayList<>());
        return ans;
    }

    private static void process(int[] nums, int i, List<List<Integer>> ans, List<Integer> tmpList) {
        if (i == nums.length) {
            ans.add(new ArrayList<Integer>(tmpList));
            return;
        }
        // 不选择
        process(nums, i + 1, ans, tmpList);
        // 选择
        tmpList.add(nums[i]);
        process(nums, i + 1, ans, tmpList);
        tmpList.remove(tmpList.size() - 1);
    }

}
